Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exceptionsToTrace configuration support in @SentinelResource annotation #543

Merged
merged 3 commits into from
Mar 25, 2019

Conversation

beston123
Copy link
Contributor

@beston123 beston123 commented Mar 5, 2019

Describe what this PR does / why we need it

In some scenarios,this resource will be degraded when it throws a specific exception.
So the configuration of exception class that should be traced (blocked), is needed.

Does this pull request fix one issue?

Fixes #540

Describe how you did it

Add the configuration of exception classes that would be traced.

Describe how to verify it

None

Special notes for reviews

None

@sczyh30 sczyh30 added the to-review To review label Mar 5, 2019
@codecov-io
Copy link

codecov-io commented Mar 5, 2019

Codecov Report

Merging #543 into master will increase coverage by 1.11%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #543      +/-   ##
============================================
+ Coverage     37.63%   38.74%   +1.11%     
- Complexity     1100     1216     +116     
============================================
  Files           259      275      +16     
  Lines          8171     8702     +531     
  Branches       1113     1163      +50     
============================================
+ Hits           3075     3372     +297     
- Misses         4697     4900     +203     
- Partials        399      430      +31
Impacted Files Coverage Δ Complexity Δ
...a/com/alibaba/csp/sentinel/node/StatisticNode.java 56.17% <0%> (-25.79%) 27% <0%> (-1%)
...slots/block/flow/controller/DefaultController.java 41.66% <0%> (-20.84%) 6% <0%> (ø)
...ibaba/csp/sentinel/eagleeye/EagleEyeLogDaemon.java 30.3% <0%> (-15.16%) 6% <0%> (-2%)
...om/alibaba/csp/sentinel/eagleeye/SyncAppender.java 53.57% <0%> (-14.29%) 5% <0%> (-1%)
...p/sentinel/slots/statistic/metric/ArrayMetric.java 67.37% <0%> (-11.58%) 29% <0%> (+1%)
.../src/main/java/com/alibaba/csp/sentinel/Entry.java 90.9% <0%> (-9.1%) 12% <0%> (ø)
...ba/csp/sentinel/slots/statistic/StatisticSlot.java 52.38% <0%> (-8.74%) 10% <0%> (ø)
.../csp/sentinel/slots/statistic/base/WindowWrap.java 71.42% <0%> (-5.5%) 6% <0%> (+1%)
...ntinel/slots/block/degrade/DegradeRuleManager.java 21.27% <0%> (-5.12%) 7% <0%> (ø)
...sp/sentinel/slots/statistic/data/MetricBucket.java 95.34% <0%> (-4.66%) 23% <0%> (+4%)
... and 48 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 10d7c90...84e2629. Read the comment docs.

Copy link
Member

@sczyh30 sczyh30 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz also reformat your code to match Alibaba Java Code Guideline.

return false;
}
for (Class exceptionToTrace : exceptionsToTrace) {
if (ex.getClass().isAssignableFrom(exceptionToTrace)) {
Copy link
Member

@sczyh30 sczyh30 Mar 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems incorrect. For each exception to trace, it should be:

Suggested change
if (ex.getClass().isAssignableFrom(exceptionToTrace)) {
if (exceptionToTrace.isAssignableFrom(ex.getClass())) {

Please be sure to add test cases and run the demo to verify it.

@@ -59,12 +59,33 @@ public Object invokeResourceWithSentinel(ProceedingJoinPoint pjp) throws Throwab
} catch (BlockException ex) {
return handleBlockException(pjp, annotation, ex);
} catch (Throwable ex) {
Tracer.trace(ex);
if (isTrackedException(ex, annotation.exceptionsToTrace())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can move the logic to AbstractSentinelAspectSupport class to support extension for sub-classes. E.g.:

protected void traceException(Throwable ex, SentinelResource annotation)

@sczyh30 sczyh30 changed the title add the configuration of exception classes that would be traced Add exceptionsToTrace configuration support in @SentinelResource annotation Mar 14, 2019
@sczyh30 sczyh30 merged commit 6e1dfb3 into alibaba:master Mar 25, 2019
@sczyh30
Copy link
Member

sczyh30 commented Mar 25, 2019

Thanks for contributing. I'll help to update the test cases and refactor code later. Please note that every new feature or enhancement must carry corresponding test cases.

@sczyh30 sczyh30 removed the to-review To review label Mar 25, 2019
@sczyh30 sczyh30 added this to the 1.5.1 milestone Mar 25, 2019
@sczyh30
Copy link
Member

sczyh30 commented Mar 25, 2019

Improved in 61c5250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add configuration of exception classes in degrade rule
3 participants